//
//  StoreCollectCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/28.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "StoreCollectCell.h"

@implementation StoreCollectCell

- (void)awakeFromNib {
    [super awakeFromNib];

    [self.firstItemControl addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.StoreCollectPackageClickBlock) {
            self.StoreCollectPackageClickBlock(0);
        }
    }];
    
    [self.secondItemControl addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.StoreCollectPackageClickBlock) {
            self.StoreCollectPackageClickBlock(1);
        }
    }];


}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [self.firstItemControl pp_clipCorners:UIRectCornerAllCorners radius:6];
        [self.secondItemControl pp_clipCorners:UIRectCornerAllCorners radius:6];
        [self.storeIcon pp_clipCorners:UIRectCornerAllCorners radius:3];

        [self.imBtn pp_clipCorners:UIRectCornerAllCorners radius:self.imBtn.frame.size.height/2];
    });
}

- (void)fillCellWithModel:(CommonCollectModel *)model {
    
    if ([model.seller.classId isEqualToString:Store_Category_Hotel]) {
        self.packageListHeight.constant = CGFLOAT_MIN;
    } else {
        
        if (model.sellerGoods.count == 0) {
            self.packageListHeight.constant = CGFLOAT_MIN;
        } else {
            self.packageListHeight.constant = 70;
        }
    }
    
    if (model.sellerGoods.count == 1) {
        self.secondItemControl.hidden = YES;
    } else {
        self.secondItemControl.hidden = NO;
    }
    
    
    NSString *url = [TT_OSSManager reSourceUrl:model.seller.logoUrl type:BA_resizeType_plus];
    [self.storeIcon sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.storeName.text = model.seller.sellerName;

    self.locationAddress.text = model.seller.sellerAddress;
//    self.starCount.text = model.seller.sellerEvaluateStar;
    
//    if (model.seller.admId == 13) {
    if (model.seller.examStatus == 2) {

        self.WYXIcon.hidden = NO;
    } else {
        self.WYXIcon.hidden = YES;
    }
    
    self.anliCount.text = [NSString stringWithFormat:@"商家案例：%ld",(long)model.sellerOpusNum];
    
    self.pingjiaCount.text = [NSString stringWithFormat:@"用户好评：%ld",(long)model.userEvaluateNum];
    
    self.youhuiquanCount.text = [NSString stringWithFormat:@"商家优惠券：%ld",(long)model.sellerCouponNum];

    self.storeQualityTag.hidden = YES;
    if (model.sellerQualityAuthentication.applyType == 1) {
        self.storeQualityTag.hidden = NO;
        [self.storeQualityTag setImage:[UIImage imageNamed:@"pingpairenzheng"]];
    } else if (model.sellerQualityAuthentication.applyType == 2) {
        self.storeQualityTag.hidden = NO;
        [self.storeQualityTag setImage:[UIImage imageNamed:@"pingzhirenzheng"]];
    } else {
        self.storeQualityTag.hidden = YES;
    }
    
    if (model.sellerGoods.count > 0) {
        CommonPackageModel *firModel = [[CommonPackageModel alloc] init];
        firModel = model.sellerGoods.firstObject;
        
        [self.firImageView sd_setImageWithURL:[NSURL URLWithString:firModel.hengUrl] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        self.firMainTitle.text = firModel.goodsName;
        self.firPriceLab.text =[NSString stringWithFormat:@"¥%@",[Utilities changeDoubleToString:firModel.goodsActivePrice]];
    }
    
    if (model.sellerGoods.count > 1) {
        CommonPackageModel *secModel = [[CommonPackageModel alloc] init];
        secModel = model.sellerGoods[1];
        
        [self.secImageView sd_setImageWithURL:[NSURL URLWithString:secModel.hengUrl] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        self.secMainTitle.text = secModel.goodsName;
        self.secPriceLab.text =[NSString stringWithFormat:@"¥%@",[Utilities changeDoubleToString:secModel.goodsActivePrice]];

    }
}


- (IBAction)goImAction:(id)sender {
    
    if (self.StoreCollectCellBlock) {
        self.StoreCollectCellBlock();
    }
    
}


@end
